import { Redirect, Route } from 'react-router-dom'
import { hasToken } from '@/utils/storage'

function AuthRouter({ component: Component, ...rest }) {
    return (
        <Route {...rest} render={(props) => {
            console.log(hasToken());
            if (hasToken()) {
                return <Component {...rest}></Component>
            } else {
                // return <Redirect to='/login'></Redirect>
                return <Redirect to={{ pathname: '/login', state: { from: props.location.pathname } }}></Redirect>
            }
        }}></Route>
    )
}

export default AuthRouter